#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int s=0;
    char ch=getchar(),last=' ';
    while(ch<'0'||ch>'9')
        last=ch,ch=getchar();
    while(ch>='0'&&ch<='9')
        s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
    return last=='-'?-s:s;
}
void write(int x)
{
    if(!x)
        putchar('0');
    char F[200];
    int tmp=x>0?x:-x;
    if(x<0)
        putchar('-');
    int cnt=0;
    while(tmp>0)
        F[cnt++]=tmp%10+'0',tmp/=10;
    while(cnt>0)
        putchar(F[--cnt]);
}
typedef struct{
	int son[11];
	bool tag;
}Tree;
Tree t[100011];
int idx;
int n;
int a[1011],b[1011];
int ans = 0;
void DFS(int p,int al,int bl)
{
	if(al == n - 1 && bl == n - 1)
	{
		if(!t[p].tag)
			ans++;
		t[p].tag = 1;
		return;
	}
	if(al < n - 1)
	{
		if(!t[p].son[b[bl + 1]])
			t[p].son[b[bl + 1]] = ++idx;
		DFS(t[p].son[b[bl + 1]],al + 1,bl);
	}
	if(bl < n - 1)
	{
		if(!t[p].son[a[al + 1]])
			t[p].son[a[al + 1]] = ++idx;
		DFS(t[p].son[a[al + 1]],al,bl + 1);
	}
}
int main()
{
	freopen("zha.in","r",stdin);
	freopen("zha.out","w",stdout);
	n = read();
	for(int i = 1;i <= n;i++)
		a[i] = read();
	for(int i = 1;i <= n;i++)
		b[i] = read();
	DFS(0,0,0);
	write(ans);
	return 0;
}
